//
//  relevanceInfo.m
//  HaiKangDemo
//
//  Created by 崔 on 2016/11/18.
//  Copyright © 2016年 崔. All rights reserved.
//  关联信息

#import "relevanceInfo.h"
#import "LGController.h"
#import <UIKit/UIKit.h>

@interface relevanceInfo () <NSCoding>




@end
@implementation relevanceInfo

+ (instancetype)relevanceInfoWithContrller:(LGController *)controller indexPath:(NSIndexPath *)indexPath{
    
    relevanceInfo *info = [[relevanceInfo alloc] init];
    
    //取真实的门信息
    NSArray *doorM = controller.doors;
    
    NSMutableArray<LGDoor *> *exactDoors= [NSMutableArray array];
    
    for (LGDoor *door  in doorM) {
        
        //如果门有名称并且能显示,过滤掉没名字,且不需要显示的门信息
        if (door.show && door.valid) {
            
            [exactDoors addObject:door];

        }
        
    }
    
    info.doorName = exactDoors[indexPath.row].doorName;
    
    info.ip = controller.ip;
    
    info.doorNo = (int)exactDoors[indexPath.row].doorIndex;
    
    info.port = controller.port;

    return info;
}

- (void)encodeWithCoder:(NSCoder *)aCoder{
    
    [aCoder encodeObject:self.controller forKey:@"controller"];
    
    [aCoder encodeObject:self.ip forKey:@"ip"];
    
    [aCoder encodeObject:self.port forKey:@"port"];
    
    [aCoder encodeObject:self.doorName forKey:@"doorName"];
    
    [aCoder encodeInt:self.doorNo forKey:@"doorNo"];
    
}

- (instancetype)initWithCoder:(NSCoder *)aDecoder{
    
    if (self = [super init]) {
        
        self.controller = [aDecoder decodeObjectForKey:@"controller"];
        
        self.ip = [aDecoder decodeObjectForKey:@"ip"];
        
        self.port = [aDecoder decodeObjectForKey:@"port"];
        
        self.doorNo = [aDecoder decodeInt32ForKey:@"doorNo"];
        
        self.doorName = [aDecoder decodeObjectForKey:@"doorName"];
        
    }
    
    return self;
    
}
@end
